package com.lhh.userservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhh.springcommon.annotation.WebLog;
import com.lhh.springcommon.annotation.WithRequestId;
import com.lhh.springcommon.entity.Collect;
import com.lhh.springcommon.entity.vo.VideoVO;
import com.lhh.springcommon.utils.PageQuery;
import com.lhh.springcommon.utils.Response;
import com.lhh.userservice.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 收藏
 * @author 李厚航
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/collect")
public class CollectController {

    private final UserCollectService userCollectService;

    @Autowired
    public CollectController(UserCollectService userCollectService) {
        this.userCollectService = userCollectService;
    }

    /**
     * 获取收藏数
     * @return
     */
    @GetMapping("/countCollect")
    @WithRequestId
    @WebLog
    public Response<Long> countCollect(@RequestParam(value = "uid",required = false) Integer uid,
                                       @RequestParam(value = "vid",required = false) Integer vid){
        return Response.success(userCollectService.countCollect(uid,vid));
    }

    /**
     * 分页查询收藏视频信息
     * @return collect集合
     */
    @GetMapping("/queryPageCollectVideo")
    @WithRequestId
    @WebLog
    public Response<Page<VideoVO>> queryPageCollectVideo(@RequestParam("page") Integer page,
                                                         @RequestParam("pageSize") Integer pageSize,
                                                         @RequestParam(value = "uid",required = false) Integer uid,
                                                         @RequestParam(value = "vid",required = false) Integer vid) {
        return Response.success(userCollectService.queryPageCollectVideo(page,pageSize,uid,vid));
    }

    /**
     * 取消收藏
     * @param collect
     * @return
     */
    @DeleteMapping("/deleteCollect")
    @WithRequestId
    @WebLog
    public Response<Boolean> deleteCollect(@RequestBody Collect collect){
        return Response.success(userCollectService.cancelCollect(collect));
    }

    /**
     * 收藏
     * @return
     */
    @PostMapping("/addCollect")
    @WithRequestId
    @WebLog
    public Response<Boolean> addCollect(@RequestBody Collect collect){
        return Response.success(userCollectService.collect(collect));
    }

    /**
     * 查询是否收藏
     * @param uid
     * @param vid
     * @return
     */
    @GetMapping("/isCollect")
    @WithRequestId
    @WebLog
    public Response<Boolean> isCollect(@RequestParam("uid") Integer uid, @RequestParam("vid") Integer vid){
        return Response.success(userCollectService.isCollect(uid,vid));
    }
}
